<?php
namespace App\Tools;
use App\Http\Controllers\Controller;
use Route;

class HgTool extends Controller{

	//无限树状结构 递归
	public function getTree($data,$pid=0,$lev=0){
		static $arr = array();
		foreach($data as $v){
			if($v['pid']==$pid){
				$v['lev'] = $lev;
				$arr[] = $v;
				$this->getTree($data,$v['id'],$lev+1);
			}	
		}
		return $arr;
	}

	//获取控制器以及方法
	public function getMethod(){
		$url = Route::getCurrentRoute()->getActionName();
		$str = ltrim(strrchr($url,'\\'),'\\');
		$data = explode('Controller@',$str);
		return $data;
	}

	// 数组整理字符串 $str key
	public function arrToStr($arr,$str){
		$data = '';
		foreach($arr as $v){
			$data .= $v[$str].',';
		}
		return rtrim($data,',');
	}

	// 二维数组转化一位数
	public function arrToArr($arr,$str){
		$data = [];
		foreach($arr as $v){
			$data[] = $v[$str];
		}
		return $data;
	}

}